package cn.zkteco.doordu.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import cn.zkteco.doordu.R;

/**
 * Created by Administrator on 2017/10/20.
 */

public class OptionsAdapter extends BaseAdapter{

    public Context mContext;
    public String[] lists;
    public LayoutInflater inflater;

    public OptionsAdapter(Context mContext){
        this.mContext = mContext;
        this.lists = mContext.getResources().getStringArray(R.array.instructions);
        this.inflater = LayoutInflater.from(mContext);
    }

    @Override
    public int getCount() {
        return lists.length;
    }

    @Override
    public Object getItem(int position) {
        return lists[position];
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View view, ViewGroup parent) {
        Holder holder;
        if (view==null){
            holder = new Holder();
            view = inflater.inflate(R.layout.item_spinner,parent,false);
            holder.cmd = view.findViewById(R.id.tv_cmd_name);
            view.setTag(holder);
        }else{
            holder = (Holder) view.getTag();
        }
        holder.cmd.setText(lists[position]);
        return view;
    }

    static class Holder{
        TextView cmd;
    }
}
